#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QString>


class QUdpSocket;
class Server;



namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    Widget(QWidget *parent,QString);
    ~Widget();

    //枚举变量用于区分消息类型 Msg聊天消息,UsrEnter新用户加入,Usrleft用户退出,FileName文件名 Refuse拒接文件
    enum MsgType{Msg,UsrEnter,UsrLeft,FileName,Refuse};

protected:
    void userEnter(QString usrname,QString ipaddr);//新用户加入
    void userLeft(QString username,QString time);   //处理用户离开
    void sndMsg(MsgType type,QString srvaddr=""); //广播UDP消息
    QString getIP();                               //获得IP
    QString getUsr();                           //获得用户名
    QString getMsg();                          //获取聊天信息

    void hasPendingFile(QString usrname,QString srvaddr,QString clntaddr,QString filename);
private:
    Ui::Widget *ui;
    QUdpSocket *udpSocket;
    qint16 port;
    QString uName;

    QString fileName;
    Server *srv;
private slots:
    void processPendingDatagrams();


    void on_sendBtn_clicked();

    void getFileName(QString);
    void on_sendTBtn_clicked();
};

#endif // WIDGET_H
